﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests
{
    [TestClass]
    public class FulcrumGenerationUnitManagerTests
    {
        public FulcrumGenerationUnitManagerTests()
        {
            // nothing
        }

        FulcrumGenerationUnitManagerTestDouble genUnitManager;

        [TestInitialize]
        public void TestInitialize()
        {
            this.genUnitManager = new FulcrumGenerationUnitManagerTestDouble();

            var genUnits = new List<GenerationUnit>();
            genUnits.Add(new MockGenerationUnit("ZFirstGenUnit"));
            genUnits.Add(new MockGenerationUnit("ASecondGenUnit"));

            this.genUnitManager.GenerationUnitSource = genUnits;
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestGetGenerationUnitNull()
        {
            this.genUnitManager.LoadGenerationUnits();

            var genUnit = this.genUnitManager.GetGenerationUnit(null);

            Assert.Fail("Exception expected");
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestGetGenerationUnitEmpty()
        {
            this.genUnitManager.LoadGenerationUnits();

            var genUnit = this.genUnitManager.GetGenerationUnit(String.Empty);

            Assert.Fail("Exception expected");
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestGetGenerationUnitBadName()
        {
            this.genUnitManager.LoadGenerationUnits();

            var genUnit = this.genUnitManager.GetGenerationUnit("not a valid gen unit");

            Assert.Fail("Exception expected");
        }

        [TestMethod]
        public void TestGetGenerationUnit()
        {
            this.genUnitManager.LoadGenerationUnits();

            var genUnit = this.genUnitManager.GetGenerationUnit("ASecondGenUnit");

            Assert.IsNotNull(genUnit);
            Assert.AreEqual("ASecondGenUnit", genUnit.Name);
        }


        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void TestGetGenerationUnitBeforeGenUnitLoad()
        {
            this.genUnitManager.GetGenerationUnit("ASecondGenUnit");

            Assert.Fail("An exception is expected");
        }

    }
}
